// pages/person/vipplas/index.js
const app = getApp()
import Toast from "../../../vant/weapp/toast/toast";
import clickreply from "../../../utils/clickreply.js";
Page({
  data: {
    store: [],
    index: 0,
    type: 1,
    cardList: [],
    listIndex: 0,
    is_user_show: true,
    is_user: 0,
    showUser: false,
    isCardList: true
  },
  onLoad(options) {
    console.log(options)
    const that = this
    let id = options.id
    let type = options.type
      app.http.post(app.api.couponinfo, {
        id
      }, (res) => {
        that.setData({
          id,
          type,
          pricecouponinfo: res.data.coupon,
        })
      })
  },
  //   登录
  login() {
    if (wx.getStorageSync('token') == "") {
      this.setData({
        is_user_show: false,
        is_user: 1
      });
    } else if (wx.getStorageSync('token') == "") {
      this.setData({
        is_user_show: false,
        is_user: 2
      });
    }
  },
  // 登录遮罩层
  close(e) {
    this.setData({
      is_user_show: e.detail,
      is_user: 0
    });
  },
  // 登陆后更新
  renew(e) {
    console.log(99, e)
    this.setData({
      showUser: true,
    });
    wx.setStorageSync("mobile", e.detail.mobile)
    wx.setStorageSync('userInfo', e.detail)
  },
  // 立即充值
  rechargeOrder() {
    if (clickreply.preventDuplicateClicks(5)) return;
    const that = this
    if (wx.getStorageSync('token') == "") {
      that.login()
      return
    }
    let id = that.data.id
    let type = that.data.type
   
if(that.data.type==1){
  app.http.post(app.api.couponOrder, {
    id
  }, (res) => {
    console.log(res.data.order_on)
    if (res.data.if_fz) {
      app.http.wecatfz(res.data.order_on, 8, (res) => {})
    } else {
      app.http.wecat(res.data.order_on, 8, (res) => {})
    }
  })
}
if(that.data.type==2){
  app.http.post(app.api.cardcouponOrder, {
    id
  }, (res) => {
    console.log(res.data.order_on)
    if (res.data.if_fz) {
      app.http.wecatfz(res.data.order_on, 9, (res) => {})
    } else {
      app.http.wecat(res.data.order_on, 9, (res) => {})
    }
  })
}



  }
});